﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.AuthorCenter.Enums;
using mozhi.smarterp.AuthorCenter.Identities;
using mozhi.smarterp.AuthorCenter.Identities.Clients;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.AuthorCenter.Controllers
{
    [RemoteService]
    [Route("api/identity/openIddict/clients")]
    public class OpenIddictClientController : AuthorCenterController
    {
        private IOpenIddictClientAppService _appService;
        public OpenIddictClientController(IOpenIddictClientAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("{name}")]
        public async Task<OpenIddictClientDto> GetAsync(string name)
        {
            return await _appService.GetAsync(name);
        }

        [HttpGet]
        public async Task<PagedResultDto<OpenIddictClientDto>> GetListAsync(PagedResultRequestDto input)
        {
            return await _appService.GetListAsync(input);
        }

        [HttpPost]
        public async Task<OpenIddictClientDto> CreateAsync(OpenIddictClientCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<OpenIddictClientDto> UpdateAsync(OpenIddictClientUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }

        [HttpDelete]
        [Route("{name}")]
        public async Task DeleteAsync(string name)
        {
            await _appService.DeleteAsync(name);
        }

        [HttpGet]
        [Route("default-permission")]
        public async Task<List<OpenIddictClientPermissionItemDto>> GetClientPermissionAsync()
        {
            return await _appService.GetClientPermissionAsync(null);
        }
    }
}
